//
//  CustomAlertView.m
//  handbook
//
//  Created by bao_wsfk on 12-8-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CustomAlertView.h"

@implementation CustomAlertView

- (void)dealloc{
    [super dealloc];
    if (timer !=nil) {
        timer = nil;
    }
    if (progressInd !=nil) {
        [progressInd stopAnimating];
        [progressInd removeFromSuperview];
        [progressInd release],progressInd = nil;
    }
}

//在使用这个方法初始化时 不要release 一定要autorelease
- (id)initAutoDismissAlert:(NSString *)title 
                   message:(NSString *)message 
                  delegate:(id)delegate 
                      time:(int)time{
    
    self = [super initWithTitle:title
                        message:message 
                       delegate:delegate 
              cancelButtonTitle:nil 
              otherButtonTitles:nil];
    
    if (self) {
        timer = [NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(dismiss) userInfo:nil repeats:NO];
    }
    return self;
}

- (void)dismiss{
    [self dismissWithClickedButtonIndex:[self cancelButtonIndex] animated:YES];
}


- (id)initWaitAlert:(NSString *)title 
            message:(NSString *)message 
           delegate:(id)delegate{
    
    self = [super initWithTitle:title
                        message:message
                       delegate:delegate 
              cancelButtonTitle:nil
              otherButtonTitles:nil];
    
    if (self) {
        //添加等待的小圆圈
        progressInd = [[UIActivityIndicatorView alloc]
                       initWithFrame:CGRectMake(35.0 , 45.0, 32.0, 32.0)];
        [progressInd startAnimating];
        progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
        [self addSubview:progressInd];
    }
    
    return self;
}

@end
